package cn.lili.controller.feign.order;

import cn.lili.modules.order.order.client.OrderItemClient;
import cn.lili.modules.order.order.entity.dos.OrderItem;
import cn.lili.modules.order.order.entity.dto.OrderItemFlowSearchParams;
import cn.lili.modules.order.order.entity.enums.CommentStatusEnum;
import cn.lili.modules.order.order.entity.vo.OrderItemFlowUserVO;
import cn.lili.modules.order.order.entity.vo.OrderItemViewVO;
import cn.lili.modules.order.order.service.OrderFlowService;
import cn.lili.modules.order.order.service.OrderItemFlowService;
import cn.lili.modules.order.order.service.OrderItemService;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 子订单实现类
 *
 * @author Chopper
 * @version v1.0 2021-12-07 18:38
 */
@RestController
@RequiredArgsConstructor
public class OrderItemFeignController implements OrderItemClient {

    private final OrderItemService orderItemService;

    private final OrderItemFlowService orderItemFlowService;

    private final OrderFlowService orderFlowService;

    @Override
    public OrderItem getBySn(String sn) {
        return orderItemService.getBySn(sn);
    }

    @Override
    public List<OrderItem> getByOrderSn(String sn) {
        return orderItemService.getByOrderSn(sn);
    }

    @Override
    public void updateCommentStatus(String sn, CommentStatusEnum finished) {
        orderItemService.updateCommentStatus(sn, finished);
    }

    @Override
    public OrderItem getByOrderSnAndSkuId(String orderSn, String skuId) {
        return orderItemService.getByOrderSnAndSkuId(orderSn, skuId);
    }

    @Override
    public void updateById(OrderItem orderItem) {
        orderItemService.updateById(orderItem);
    }

    @Override
    public void saveBatch(List<OrderItem> orderItems) {
        orderItemService.saveBatch(orderItems);
    }

    /**
     * 修改订单投诉状态
     *
     * @param orderItemIdList 获取订单货物ID
     * @return 是否操作成功
     */
    @Override
    public boolean updateComplainStatus(List<String> orderItemIdList) {
        return orderItemService.updateComplainStatus(orderItemIdList);
    }

    @Override
    public void update(OrderItem orderItem) {

        LambdaUpdateWrapper<OrderItem> lambdaUpdateWrapper = new LambdaUpdateWrapper<OrderItem>()
                .eq(OrderItem::getOrderSn, orderItem.getOrderSn())
                .set(OrderItem::getAfterSaleStatus, orderItem.getAfterSaleStatus())
                .set(OrderItem::getCommentStatus, orderItem.getCommentStatus());

        orderItemService.update(lambdaUpdateWrapper);
    }

    @Override
    public Page<OrderItemFlowUserVO> getOrderFlowUserVOByCondition(OrderItemFlowSearchParams searchParams) {
        return orderItemFlowService.getOrderFlowUserVOByCondition(searchParams);
    }

    @Override
    public Long amountOderFlowUserVOByCondition(OrderItemFlowSearchParams searchParams) {
        return orderItemFlowService.amountOderFlowUserVOByCondition(searchParams);
    }

    @Override
    public OrderItem getByIdVal(String orderItemIdVal) {
        LambdaUpdateWrapper<OrderItem> lambdaUpdateWrapper = new LambdaUpdateWrapper<OrderItem>();
        lambdaUpdateWrapper.eq(OrderItem::getOrderItemIdVal,orderItemIdVal);
        lambdaUpdateWrapper.last("limit 1");
        return orderItemService.getOne(lambdaUpdateWrapper);
    }

    /**
     * 查询店主的直推业绩,佣金收益总数
     * @param memberIds
     * @return
     */
    @Override
    public List<OrderItemViewVO> getDistributionFlowPriceAndComissTotal(List<String> memberIds) {
        return orderFlowService.getDistributionFlowPriceAndComissTotal(memberIds);
    }

    @Override
    public List<OrderItemViewVO> getDistributionFlowPriceAndComissTotalCurrentMonth(List<String> memberIds) {
        return orderFlowService.getDistributionFlowPriceAndComissTotalCurrentMonth(memberIds);
    }

    @Override
    public List<OrderItemViewVO> getDistributionFlowPriceAndComissTotalLastMonth(List<String> memberIds) {
        return orderFlowService.getDistributionFlowPriceAndComissTotalLastMonth(memberIds);
    }

    @Override
    public List<OrderItemViewVO> getDistributionFlowPriceAndComissTotalDistribution(List<String> memberIds) {
        return orderFlowService.getDistributionFlowPriceAndComissTotalDistribution(memberIds);
    }

    @Override
    public OrderItemViewVO getDistributionFlowPriceAndComissTotalByMonth(String memberId, String startTime, String endTime) {
        return orderFlowService.getDistributionFlowPriceAndComissTotalByMonth(memberId,startTime,endTime);
    }

    @Override
    public List<OrderItemViewVO> getDistributionFlowPriceAndComissTotalType(List<String> memberIds, Integer type) {
        return orderFlowService.getDistributionFlowPriceAndComissTotalType(memberIds, type);
    }
}
